// this is clent for watcher
'use strict';
const net = require('net');
const LDJClient = require('./lib/ldj-client.js');
let port=60030

const client = net.connect({port:port});
const ldjClient= LDJClient.connect(client);
ldjClient.on('message',message=>{
    //const message = JSON.parse(data);
    if (message.type === 'watching'){
        console.log(`Now Watching ${message.file}`);
    }else if (message.type === 'changed'){
        const date = new Date(message.timestamp);
        console.log(`File changed: ${date}`);
    }else{
        console.log(`Unrecognized message type: ${message.type}`);
    }

});
client.on('error',err=>{
    console.log(`${err}`);
}).on('end',()=>{
    console.log('Connection closed.');

});
process.on('SIGINT',()=>{
    console.log('closing...');
    client.end();
});
